import request from '@/utils/request_app'
import { getUserInfo } from '@/api/login/login'

// 意见反馈
export const submitFeedbackApi = data => {
  return request({
    url: 'app/sys/cmsContent/feedback',
    method: 'post',
    data: data,
  })
}

// 举报评论
export const reportCommentApi = data => {
  return request({
    url: 'app/sys/cmsContent/report',
    method: 'post',
    data: data,
  })
}

// 屏蔽评论
export const shieldCommentApi = data => {
  return request({
    url: 'app/sys/cmsContent/shield',
    method: 'post',
    data: data,
  })
}

//客户端上报(推送配置及设备配置)数据接口
export const reportUserClientApi = data => {
  return request({
    url: 'app/common/reportUserClient',
    method: 'post',
    data: data,
  })
}

//客户端上报(推送配置及设备配置)数据接口
export const reportClientData = async () => {
  // #ifdef APP-PLUS
  try {
    let clientId = uni.$PushClientId
    console.log(clientId, 'clientId-----------')
    if (!clientId) {
      return
    }

    let userClient = {
      pushClientId: clientId,
    }

    let token = uni.getStorageSync('Token')
    let userInfo = uni.getStorageSync('UserInfo')

    if (userInfo && userInfo.id) {
      userClient.userId = userInfo.id
    } else if (token) {
      try {
        const res = await getUserInfo()
        console.log('token=', token, 'userInfo=', res, '-------------')
        if (res && res.id) {
          userClient.userId = res.id
        }
      } catch (err) {
        console.log(err)
      }
    }

    let sysInfo = uni.getSystemInfoSync()
    userClient.deviceId = sysInfo.deviceId
    userClient.os = sysInfo.osName
    userClient.deviceBrand = sysInfo.deviceBrand
    userClient.deviceModel = sysInfo.deviceModel
    userClient.userRole = 1 //1-C端用户
    userClient.appType = 2 //2-炎华潮玩APP

    //reportUserClientApi(userClient);

    request({
      url: 'app/common/reportUserClient',
      method: 'post',
      data: userClient,
    }).catch(err => {
      console.log(err, 'reportUserClient 获取数据失败err')
    })

    console.log('reportUserClientApi.........')
  } catch (e) {
    //TODO handle the exception
    console.log(e)
  }
  // #endif
}

export default {
  submitFeedbackApi,
  reportCommentApi,
  shieldCommentApi,
  reportUserClientApi,
}

// 举报评论
export const reportCommentApiNew = data => {
  return request({
    url: 'app/sys/cmsContent/report',
    method: 'post',
    data: data,
  })
}
// 屏蔽评论
export const shieldCommentApiNew = data => {
  return request({
    url: 'app/sys/content/shield',
    method: 'post',
    data: data,
  })
}
//contentReport
export const contentReport = data => {
  return request({
    url: 'app/sys/content/report',
    method: 'post',
    data: data,
  })
}

// 广告图管理
export const getAdvertisingBannerList = data => {
  return request({
    url: 'app/sys/content/list',
    method: 'post',
    data: data,
  })
}
// 2022-11-16 发送-推送
export const pushMessage = data => {
  return request({
    url: 'app/im/chat/push',
    method: 'post',
    data,
  })
}

// 新版 广告位 管理
export const getNewAdvertisingBannerList = data => {
  return request({
    url: 'app/sys/content/newList',
    method: 'post',
    data: data,
  })
}
